package com.sy.notice;

import com.sy.notice.biz.eventnotice.SendMsg;
import com.sy.notice.util.HttpClientUtil;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.function.Supplier;

/**
 * @author 舒祥
 * @date 2022-01-25
 * @desc bark app推送消息
 */
public class SendMsgToBark implements SendMsg<String> {
    /**
     * 标题的推送方式   bark支持很多种方式的推送  todo 占时搞这一种
     * https://api.day.app/{your appSecretKey}/推送标题/这里改成你自己的推送内容
     */
    public static final String barkUrl = "https://api.day.app/";


    /**
     * @param appSecretKey
     * @param msg
     */
    @Deprecated
    public String sendMsg(String appSecretKey, String msg) throws Exception {
        String topic = URLEncoder.encode("事件提醒", "utf-8");
        msg = URLEncoder.encode(msg, "utf-8");
        String url = barkUrl + appSecretKey + "/" + topic + "/" + msg;
        HttpClientUtil httpClientUtil = new HttpClientUtil();
        return httpClientUtil.doGet(url);
    }

    public static void main(String[] args) throws Exception {
//        String url =  "https://api.day.app/{your sk}/%E4%BA%8B%E4%BB%B6%E6%8F%90%E9%86%92/10%E7%82%B9%E5%87%86%E5%A4%87%E5%BC%80%E4%BC%9A";
//        HttpClientUtil httpClientUtil = new HttpClientUtil();
//        System.out.println(httpClientUtil.doGet(url));
    }

    @Override
    public String sendMsg(Supplier msgSupplier, Supplier paramsSupplier) throws Exception {
        String msg = (String) msgSupplier.get();
        String appSecretKey = (String) paramsSupplier.get();
        String topic = URLEncoder.encode("事件提醒", "utf-8");
        msg = URLEncoder.encode(msg, "utf-8");
        String url = barkUrl + appSecretKey + "/" + topic + "/" + msg;
        HttpClientUtil httpClientUtil = new HttpClientUtil();
        return httpClientUtil.doGet(url);
    }
}
